<?php
/**
 * Configuration file
 * 
 * This file offers some configuration
 * variables that will be available
 * in the whole application.  
 * 
 * @author Gabriel PREDA
 * @copyright  Copyright (c) 2008-2009 Acceleron Team
 * @version    $Id: Config.php 36 2008-12-02 21:46:16Z gabriel.preda $
 */

class Config
{
/**
 * SiteConfigurator instance
 *
 * @var SINGLETON-instance
 */
private static $instance;

private $AlertEmail;
private $SMTP;
private $EHLO;
private $ApplicationVersionMajor;
private $ApplicationVersionMinor;
private $ApplicationVersionPatch;
private $ApplicationVersionString;

/**
 * You have no reasons to modify below this line.
 *
 */

/**
 * Object construnctor
 * @return Config
 */
private function __construct()
{
	$this->ParseIniFile('config.ini');

	$this->ApplicationVersionString = $this->ApplicationVersionMajor
		. '.'
		. str_pad($this->ApplicationVersionMinor, 2, 0, STR_PAD_LEFT)
		. '.'
		. $this->ApplicationVersionPatch;
}

/**
 * Global getter
 *
 * @param string $Var
 * @return mixed
 */
public function __get($Var) {
	$Var = trim($Var);
	if ('private' === $Var) {
		return 0;
	}
	
	return $this->$Var;
}

/**
 * Get the instance of the object or 
 * construct a new one if necessary
 *
 * @return Config
 */
public static function GetInstance()
{
    if (!isset(self::$instance))
    {
            $c = __CLASS__;
            self::$instance = new $c;
    }

    return self::$instance;
}

/**
 * Parse the INI file and initialize variables
 *
 * @param string $ConfigFile
 */
private function ParseIniFile($ConfigFile = 'Config.ini')
{
	$ConfigFile = parse_ini_file($ConfigFile, true);

	if (isset($ConfigFile['Global']))
	{
		$this->AssignAttributes($ConfigFile['Global']);
	}

	if (isset($ConfigFile[ $_SERVER['SERVER_NAME'] ]))
	{
		$this->AssignAttributes($ConfigFile[ $_SERVER['SERVER_NAME'] ]);
	}
}

/**
 * Assign for each value of the array the value from ini file overriding as necesarry
 *
 * @param array $Attrs
 */
private function AssignAttributes($Attrs)
{
	foreach ($Attrs as $AttrIndex => $AttrValue)
	{
		$this->$AttrIndex = $AttrValue;
	}
}

public function __clone()
{
	trigger_error('Clone is not allowed.', E_USER_ERROR);
}

}

class ConfigException extends AcceleronException { }
